<template>
  <div class="my">
    <div class="user">
      <!-- <div class="userTop" @click="toLogin" v-if="show">
        <img class="img" src="@/assets/touxiang@2x.png" alt="" />
        <span>登录/注册</span>
      </div> -->
      <div class="userTop" @click="toLogin">
        <img v-if="info.userImage" class="img" :src="info.userImage" alt="" />
        <img v-else class="img" src="@/assets/touxiang@2x.png" alt="" />
        <div class="right">
          <span v-if="info.userName">{{ info.userName }}</span>
          <span v-else>登录/注册</span>
          <div v-if="info.userName" class="bianji">编辑资料</div>
        </div>
      </div>
      <div class="userBottom">
        <div class="item">
          <span class="o1">{{ info.noteCount }}</span>
          <span class="o2">发布</span>
        </div>
        <div class="item">
          <span class="o1">{{ info.markCount }}</span>
          <span class="o2">评论</span>
        </div>
        <div class="item">
          <span class="o1">{{ info.recommendCount }}</span>
          <span class="o2">关注</span>
        </div>
        <div class="item">
          <span class="o1">{{ info.fansCount }}</span>
          <span class="o2">粉丝</span>
        </div>
      </div>
    </div>
    <div class="row-list">
      <div class="point">
        <div class="left">
          <i class="iconfont">&#xe60d;</i>
          <div class="num">
            <div class="val">{{ info.integralVal }}</div>
            <div class="text">积分</div>
          </div>
        </div>
        <div class="right">
          <span>兑豪礼</span>
        </div>
      </div>
      <div class="row-item"></div>
    </div>
    <div class="cell">
      <!-- 任务中心 -->
      <van-cell is-link>
        <template #icon>
          <i class="iconfont">&#xe60b;</i>
        </template>
        <template #title>
          <div class="title">任务中心</div>
        </template>
      </van-cell>
      <!-- 我的消息 -->
      <van-cell is-link>
        <template #icon>
          <i class="iconfont">&#xe600;</i>
        </template>
        <template #title>
          <div class="title">我的消息</div>
        </template>
      </van-cell>
      <!-- 我的预约 -->
      <van-cell is-link>
        <template #icon>
          <i class="iconfont">&#xe6b2;</i>
        </template>
        <template #title>
          <div class="title">我的预约</div>
        </template>
      </van-cell>
      <!-- 我的收藏 -->
      <van-cell is-link>
        <template #icon>
          <i class="iconfont">&#xe623;</i>
        </template>
        <template #title>
          <div class="title">我的收藏</div>
        </template>
      </van-cell>
      <!-- 语言设置 -->
      <van-cell is-link>
        <template #icon>
          <i class="iconfont">&#xe602;</i>
        </template>
        <template #title>
          <div class="title">语言设置</div>
        </template>
      </van-cell>
    </div>
  </div>
</template>

<script>
import { myInfo } from '@/api/my.js'
import { mapState } from 'vuex'
export default {
  name: 'my',
  computed: {
    ...mapState(['userInfo', 'isLogin'])
  },
  data () {
    return {
      showOut: true,
      show: false,
      // 从vuex中获取id
      userId: this.$store.state.userInfo.userId,
      info: ''
    }
  },
  async created () {
    const res = await myInfo({ userId: this.userId })
    console.log('info', res)
    this.info = res.data.data
  },
  methods: {
    toLogin () {
      // 逻辑： 判断如果已经登录测跳转到编辑界面，否则跳转到登录页面
      // this.$router.push('/login')
    }
  }
}
</script>

<style lang="less">
.my {
  width: 100%;
  .user {
    padding: 0 15px;
    height: 200px;
    background-image: url(~@/assets/homepage_bg@2x.png);
    .userTop {
      padding-top: 55px;
      display: flex;
      align-items: center;
      .img {
        border-radius: 50%;
        width: 68px;
        height: 68px;
        border: 1px solid #000;
      }
      span {
        flex: 1;
        padding-left: 20px;
        font-size: 20px;
        font-weight: 700;
      }
      .right {
        .bianji {
          padding-left: 20px;
          font-size: 14px;
        }
      }
    }
    .userBottom {
      padding: 0 15px;
      margin-top: 18px;
      display: flex;
      justify-content: space-between;
      .item {
        flex-direction: column;
        text-align: center;
        .o1 {
          display: block;
          font-size: 16px;
          font-weight: 700;
        }
        .o2 {
          display: block;
          font-size: 14px;
          color: #9fa0a0;
        }
      }
    }
  }
  .row-list {
    padding: 15px 15px;
    .point {
      height: 70px;
      border: 1px solid #e5f3ff;
      background-color: #f0f8ff;
      padding: 0 15px;
      border-radius: 10px;
      display: flex;
      align-items: center;
      justify-content: space-between;
      .left {
        display: flex;
        align-items: center;
        .iconfont {
          display: block;
          font-size: 30px;
          color: #6cb8ff;
        }
        .num {
          padding-left: 15px;
          font-size: 12px;
          .val {
            font-weight: 700;
          }
          .text {
          }
        }
      }
      .right {
        color: #2d9aff;
        font-weight: 500;
        font-size: 16px;
        span {
          padding: 10px 15px;
          border: 2px solid #2d9aff;
          border-radius: 5px;
        }
      }
    }
  }
  .cell {
    .iconfont {
      font-weight: 700;
    }
    .title {
      padding-left: 10px;
    }
  }
  .btn {
    .getOut {
      font-weight: 700;
    }
  }
}
</style>
